<?php
if ($_POST['edit']!='')
{
   $cmd="UPDATE `comment` SET comment_text='".$_POST['content']."' WHERE comment_id=".$_GET['edit'];
   mysql_query($cmd);
   echo 'Đã sửa xong comment !';
} else
  if (isset($_GET['edit']))
  {
     $cmd="SELECT * FROM `comment` WHERE comment_id=".$_GET['edit'];
	 $info=mysql_fetch_assoc(mysql_query($cmd));
     echo'<form method="post" enctype="multipart/form-data"><div class="selecttitle"><b><a>Nội dung comment</a></b></div>
	<div class="selecttitle"><textarea name="content">'.$info['comment_text'].'</textarea></div>
	<input type="submit" class="buttonclick" value="Sửa" name="edit"/>
	</form>';
  } else
  {
  if (isset($_GET['del']))
  {
     $cmd="DELETE FROM `comment` WHERE comment_id=".$_GET['del'];
	 mysql_query($cmd);
  }  
 echo '<table width="775" border="1" class="viewmd" cellpadding="10" cellspacing="0">
  <th width="30px">ID</th>
  <th width="70px">Poster</th>
  <th width="160px">Song/Album</th>
  <th>Detail</th>
  <th width="60px">Time</th>
  <th width="40px">Edit</th>
  <th width="40px">Del</th>';
	  $sql="SELECT * FROM `comment` ORDER BY comment_time DESC";
	  $excute=mysql_query($sql);
	  while ($row=mysql_fetch_array($excute,MYSQL_ASSOC))
	  {
		  echo'<tr><td>';
		  echo $row['comment_id']; echo '</td><td>';
		  echo finduser($row['comment_poster']); echo '</td>';
		  if ($row['comment_media']!=0) { $ksong='media'; $cmid=$row['comment_media'];} else {$ksong='album';$cmid=$row['comment_album'];}
		  
		  $cmd="SELECT * FROM `".$ksong."` WHERE ".$ksong."_id=".$cmid;
		  $info=mysql_fetch_assoc(mysql_query($cmd));
		  echo '<td><a href="'.$row[comment_link].'">'.$info[$ksong.'_name'].'</a></td><td>';
		  echo readmore($row['comment_text'],5); echo '<a title="'.$row['comment_text'].'"> readmore</a></td><td>';
		  echo changetime($row['comment_time']).'</td>';
		  echo '<td><div class="buttons"><a class="button flag" href="?menu=comment&edit='.$row['comment_id'].'">Sửa</a></div></td>';
echo '<td><div class="buttons"><a class="button delete" href="?menu=comment&del='.$row['comment_id'].'">Xóa</a></div></td></tr>';
	  } 
	  echo '</table>';
}
?>


